|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| DateUtil.java | 75% | 78.6% | 50% | 75% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* Created on Aug 19, 2004
|
|
| 3 |
*/
|
|
| 4 |
package org.marketchangers.prayer;
|
|
| 5 |
|
|
| 6 |
import java.text.ParseException;
|
|
| 7 |
import java.text.SimpleDateFormat;
|
|
| 8 |
import java.util.Date;
|
|
| 9 |
import java.util.StringTokenizer;
|
|
| 10 |
|
|
| 11 |
/**
|
|
| 12 |
* @author <a href="mailto:jniu@wc-group.com">Jianshuo Niu</a>
|
|
| 13 |
*
|
|
| 14 |
*/
|
|
| 15 |
public class DateUtil { |
|
| 16 | 0 |
public DateUtil(){
|
| 17 | 0 |
super();
|
| 18 |
} |
|
| 19 | 54 |
public static Date validateDateField(String field){ |
| 20 |
|
|
| 21 | 54 |
if (field == null) { |
| 22 | 0 |
return null; |
| 23 |
} |
|
| 24 |
|
|
| 25 | 54 |
StringTokenizer token = new StringTokenizer(field, "-"); |
| 26 |
|
|
| 27 |
//validate date
|
|
| 28 | 54 |
try {
|
| 29 | 54 |
int month = Integer.parseInt(token.nextToken());
|
| 30 | 46 |
int day = Integer.parseInt(token.nextToken());
|
| 31 | 46 |
int year= Integer.parseInt(token.nextToken());
|
| 32 |
/*
|
|
| 33 |
System.out.println("year: "+year);
|
|
| 34 |
System.out.println("month: "+month);
|
|
| 35 |
System.out.println("day: "+day);
|
|
| 36 |
*/
|
|
| 37 | 46 |
if (12 <month || month < 1 || 31 < day || day < 1||year<1900) {
|
| 38 | 6 |
return null; |
| 39 |
} |
|
| 40 |
} catch (Exception e) {
|
|
| 41 | 8 |
return null; |
| 42 |
} |
|
| 43 |
|
|
| 44 | 40 |
try {
|
| 45 | 40 |
return new SimpleDateFormat("MM-dd-yyyy").parse(field); |
| 46 |
} catch (ParseException e) {
|
|
| 47 | 0 |
return null; |
| 48 |
} |
|
| 49 |
} |
|
| 50 |
|
|
| 51 |
} |
|
| 52 |
|
|
||||||||||